<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateNotificationConfigTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('notification_config', ['comment' => '消息通知配置', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('event', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '消息事件'])
            ->addColumn(Column::enum('channel', ['Sms', 'Email', 'Websocket', 'WechatOfficialAccount', 'WechatMiniProgram', 'WechatOfficialAccountBizsend'])->setNull(true)->setDefault(null)->setComment('发送渠道:Sms=短信,Email=邮件,Websocket=Websocket,WechatOfficialAccount=微信模板消息,WechatMiniProgram=小程序订阅消息,WechatOfficialAccountBizsend=公众号订阅消息'))
            ->addColumn(Column::enum('type', ['default', 'custom'])->setNull(true)->setDefault(null)->setComment('类型:default=默认,custom=自定义'))
            ->addColumn('content', 'text', ['null' => true, 'default' => null, 'comment' => '配置内容'])
            ->addColumn(Column::enum('status', ['enable', 'disabled'])->setDefault('enable')->setComment('状态:enable=开启,disabled=关闭'))
            ->addColumn('send_num', 'integer', ['limit' =>  10, 'default' => 0, 'comment' => '发送次数'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('notification_config');
        $table->drop();
    }
}
